package com.yzf.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yzf.entity.Employee;
import com.yzf.entity.Idea;
import com.yzf.entity.IdeaComment;
import com.yzf.service.IdeaCommentService;
import com.yzf.service.IdeaService;
import com.yzf.util.util.DateTimeUtil;
import com.yzf.util.web.ServletUtil;

public class ShowIdeaServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		HttpSession session = ServletUtil.getSession(request);
		String iid = request.getParameter("id");
		
		IdeaService service = new IdeaService();
		Idea idea = service.findByIid(iid);
		session.setAttribute("idea", idea);
		
		
		Employee em = (Employee)session.getAttribute("employee");
		
		IdeaCommentService service2 = new IdeaCommentService();
		List<IdeaComment> commentList = service2.findByEidIid(em.getId(),iid);
		
		
		for (int i = 0; i < commentList.size(); i++) {
					
			IdeaComment comment2 = commentList.get(i);
					String time = comment2.getCreatetime();
					
					String time2 = DateTimeUtil.getTimeForShowing(time);
					comment2.setTime(time2);
				}
		request.setAttribute("commentList", commentList);
		
		ServletUtil.forword(request, response, "idea_show");
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

}
